<template>
  <div class="rightTable">
    <slot name="header"></slot>
    <div class="main">
      <el-table
        :data="tableData"
        current-row-key="id"
        height="calc(100vh - 255px)"
      >
        <!-- <el-table-column v-show="hasNumber" prop="ord" label="序号" min-width="50"> </el-table-column> -->
        <el-table-column
          v-for="col in cols"
          :key="col.prop"
          :prop="col.prop"
          :label="col.label"
          :min-width="col.width || 'auto'"
        >
        </el-table-column>
        <slot name="operation"></slot>
      </el-table>
    </div>
    <div class="footer">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageIndex"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'baseTable',
  props: {
    cols: {
      type: Array,
      defautl: [],
    },
    page: {
      type: Object,
      require: true,
    },
    tableData: {
      type: Array,
      defautl: [],
    },
    hasNumber: {
      type: Boolean,
      defautl: true,
    },
  },
  data() {
    return {}
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.$emit('update:page', { ...this.page, pageSize: val })
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.$emit('update:page', { ...this.page, pageIndex: val })
    },
  },
}
</script>

<style lang="scss" scoped>
.rightTable {
  width: 100%;
  height: calc(100% - 20px);
  box-sizing: border-box;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  .main {
    flex: 1;
    margin-top: 30px;
    .range {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      &-main {
        width: 60px;
        height: 5px;
        background: #f1f5fa;
        border-radius: 3px;
        position: relative;
        overflow: hidden;
      }
      &-inner {
        position: absolute;
        z-index: 1;
        width: 50%;
        height: 100%;
        background: #10a6dd;
      }
      &-text {
        margin-left: 10px;
        font-size: 14px;
        color: #717689;
      }
    }
  }
  .footer {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
}
.btn {
  background: #10a6dd;
  border-radius: 4px;
  height: 34px;
  line-height: 34px;
  padding: 0 20px;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
</style>
